/**
 * 版权所有 2009-2012山东新北洋信息技术股份有限公司
 * 保留所有权利。
 */
package com.linyaonan.leetcode.easy._03_04;

import java.util.LinkedList;
import java.util.Stack;

/**
 * @ProjectName: leetcode
 * @Package: com.linyaonan.leetcode.easy._03_04
 * @ClassName: MyQueue
 * @Author: linyaonan
 * @Date: 2020/3/26 16:13
 */
public class MyQueue {
    private Stack<Integer> oneStack;
    private Stack<Integer> twoStack;
    /** Initialize your data structure here. */
    public MyQueue() {
        oneStack = new Stack<>();
        twoStack = new Stack<>();
    }

    /** Push element x to the back of queue. */
    public void push(int x) {
        while (!twoStack.isEmpty()) {
            oneStack.push(twoStack.pop());
        }
        // 添加新元素
        oneStack.push(x);
        while (!oneStack.isEmpty()) {
            twoStack.push(oneStack.pop());
        }

    }

    /** Removes the element from in front of queue and returns that element. */
    public int pop() {
        return twoStack.pop();
    }

    /** Get the front element. */
    public int peek() {
        return twoStack.peek();
    }

    /** Returns whether the queue is empty. */
    public boolean empty() {
        return twoStack.isEmpty() && oneStack.isEmpty();
    }
}
